package cn.edu.zafu.bigdata.yh;
import java.io.*;
import  java.net.*;

public class Server{
    public static void main(String[] args){
        int port = 6666;
        try{
            ServerSocket serverSocket=new ServerSocket(port);
            System.out.println("Server is running and waiting for client on port"+port);
            while(true){
                Socket socket =serverSocket.accept();
                System.out.println("Clint connected");

                BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                PrintWriter output =new PrintWriter(socket.getOutputStream(),true);

                String clientMessage= input.readLine();
                System.out.println("Message from client:"+clientMessage);

                output.println("Hello client!I received your message:"+clientMessage);
                socket.close();
            }
        } catch (IOException e){
            e.printStackTrace();
        }
    }
}
